package com.kmxd.ams.infra.utils;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.collect.Lists;
import com.kmxd.ams.client.archive.vo.ArchiveRuleFieldListVO;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 分组
 *
 * @author nickbi
 */
public class GroupUtil {

  public static <T> List<Object> buildKey(T source, List<ArchiveRuleFieldListVO> fieldSet) {
    Map<String, Object> documentMap = BeanUtil.beanToMap(source);
    ArrayList<Object> objects = Lists.newArrayList();
    fieldSet.forEach(
        filed -> objects.add(documentMap.get(StringUtils.underlineToCamel(filed.getFieldCode()))));
    return objects;
  }

  public static <T> List<Object> buildKeyByField(T source, List<String> fieldList) {
    Map<String, Object> documentMap = BeanUtil.beanToMap(source);
    ArrayList<Object> objects = Lists.newArrayList();
    fieldList.forEach(filed -> objects.add(documentMap.get(StringUtils.underlineToCamel(filed))));
    return objects;
  }
}
